<%@ page language="java" %>

<%@ page import="java.util.*,
                 java.net.*,
                 java.lang.*,
                 com.broadvision.ssp.client.SspInstance,
                 com.broadvision.web.util.ViewDynaBean,
		 org.apache.struts.validator.DynaValidatorForm,
                 org.apache.commons.beanutils.PropertyUtils"
%>

<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>

<script language="JavaScript">
   function doAttachment(theForm,value){
     theForm.filePath.value=value;
     var theURL="/cm/contentAttachDetail.do";
     theForm.action='<html-el:rewrite page="'+theURL+'" />';
     theForm.submit();
     return true;
   }
</script>
<jsp:useBean id="searchResultView" scope="request" type="com.broadvision.web.util.ViewDynaBean"/> 
<bean-el:size id="resultSize" name="searchResultView" property="resultList"/>

<% 
   String ctxPath = request.getContextPath(); 
   ViewDynaBean view = (ViewDynaBean) request.getAttribute("searchResultView"); 
   Integer totalCount = (Integer) PropertyUtils.getSimpleProperty(view, "totalCount");
%>
   
<script language="javascript">

 function doWebflowAction(theForm,cntOID,version,cntAction){
   var theURL="/cm/launchVSWebflow.do";
   var theParam="?guid="+cntOID+"&version="+version+
             "&launchAction="+cntAction+"&exitURL="+"/cm/closeWindow.do";
   var url ='<html-el:rewrite page="'+theURL+'" />'+theParam;
   var qualifier = window.open(url, "ContentServiceLaunchProcess",
                               "directories=no,height=500,width=650,left=50,top=50,resizable=yes,scrollbars=yes,location=yes,menubar=yes,status=yes,toolbar=yes");

  if (qualifier != null){
    if (qualifier.opener == null)
        qualifier.opener = self;
    qualifier.focus();
  }


 }
 function doAction(theForm,cntOID,version,cntAction){
   var theURL="/cm/cmProcessMapping.do";
   var theParam="?contentOID="+cntOID+"&version="+version+"&contentAction="+cntAction;
   var url ='<html-el:rewrite page="'+theURL+'" />'+theParam;
   var qualifier = window.open(url, "ContentServiceLaunchProcess",
                              "directories=no,height=500,width=650,left=50,top=50,resizable=yes,scrollbars=yes,location=yes,menubar=yes,status=yes,toolbar=yes");

   if (qualifier != null){
     if (qualifier.opener == null)
         qualifier.opener = self;
    qualifier.focus();
  }

 }

 function doBVAction(theForm,cntOID,cntTypeId,catOID,cntAction){
   var theURL="/cm/cmBVCProcessMapping.do";
   var theParam="?contentOID="+cntOID+"&categoryOID="+catOID+"&contentTypeId="+cntTypeId+"&contentAction="+cntAction+"&exitURL=/cm/closeWindow.do";
   var url ='<html-el:rewrite page="'+theURL+'" />'+theParam;
   var qualifier = window.open(url, "ContentServiceLaunchProcess",
                              "directories=no,height=500,width=650,left=50,top=50,resizable=yes,scrollbars=yes,location=yes,menubar=yes,status=yes,toolbar=yes");

   if (qualifier != null){
     if (qualifier.opener == null)
         qualifier.opener = self;
    qualifier.focus();
  }
 }

function doGoCnt(formName) {
  var thisForm = document.forms[formName];
  if (thisForm != null) {
      thisForm.pageNum.value = 1;
      thisForm.submit();
  }
  return false;
}

function gotoPage(formName, pageNum) {
  var thisForm = document.forms[formName];
  if (thisForm != null) {
    thisForm.pageNum.value = pageNum;
    thisForm.submit();
  }
}

function setCSAction(theForm) {
  theForm.curVersion[0].disabled=false;
  theForm.curVersion[1].disabled=false;
  theForm.sortBy.disabled= false;
  theForm.curVersion[0].checked=true;
  return true;
}
function setRuntimeAction(theForm) {
  theForm.curVersion[0].disabled=true;
  theForm.curVersion[1].disabled=true;
  theForm.sortBy.disabled= "checked";
  return true;
}
function onSubmit(myform) {

  if (myform.fulltextQuery.value.length == 0){
     alert('<bean-el:message bundle="cm.messages" key="cm.content.search.nocriteria"/>');
     return false;
   }
   myform.submit();
  return true;
}
function doRefresh() {
  return onSubmit(document.forms["cmBasicSearchForm"]);
}

function doUncheckout(theForm, contentOid) {
  theForm.action = '<html-el:rewrite page="/cm/uncheckOut.do"/>';
  theForm.contentOid.value = contentOid;
  theForm.submit();
  return false;
}  

</script>

<jsp:useBean id="cmContentAdmin" scope="session" type="java.lang.Boolean"/>

<html-el:form action="/cm/cmBasicSearch.do?action=search">
<html-el:hidden property="pageNum" value="1" />
<html-el:hidden property="filePath" />
<input type="hidden" name="contentOid"/>

<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="<bean-el:message bundle='cm.messages' key='cm.content.contentSearch'/>">

  <tr> 
  <td valign="top" width="100%">
		  
  <div class="pageTitle"><bean-el:message bundle='cm.messages' key='cm.content.contentSearch'/></div>

<%@include file="/mc/common/pagetab.jsp" %>
  <div class="pageSubtitle">
    <span class="left"><bean-el:message bundle='cm.messages' key='cm.content.searchCriteria'/></span>
    <span class="right">&nbsp;</span>
  </div> 
           
  <table class="labelForm" width="100%" border="0" cellspacing="0" cellpadding="0" summary="<bean-el:message bundle='cm.messages' key='cm.content.contentSearch'/>">
         
  <!--start main content here-->
 
    <c:if test="${searchResultView.map.fulltextSearchEnabled}">
      <tr>
        <td width="20%" class="label"><bean-el:message bundle='cm.messages' key='cm.content.fulltextQuery'/>:</td>
        <td class="labelField" width="50%" >
          <html-el:text name="searchResultView" property="fulltextQuery" maxlength="100" size="50" />
        </td>
        <td class="labelField" width="30%" > &nbsp;&nbsp</td>
      </tr>
    </c:if>

     <tr> 
        <td width="20%" class="label">&nbsp;</td>
        <td class="labelField" width="50%" >
          <html-el:radio property="type" value="1" onclick="setRuntimeAction(this.form)" >
              <bean-el:message bundle='cm.messages' key='cm.content.search.runtime'/>&nbsp;
              <html-el:link page="/cm/cmBVContentSearch.do" > <bean-el:message bundle='cm.messages' key='cm.content.search.adv'/>
              </html-el:link>
          </html-el:radio>
        </td>
        <td class="labelField" width="30%" > &nbsp;&nbsp</td>
     </tr>
     <tr> 
        <td width="20%" class="label">&nbsp;</td>
        <td class="labelField" width="20%" >
          <html-el:radio property="type" value="0" onclick="setCSAction(this.form)" >
              <bean-el:message bundle='cm.messages' key='cm.content.search.cs' />&nbsp;
              <html-el:link page="/cm/cmCSSearch.do" > <bean-el:message bundle='cm.messages' key='cm.content.search.adv'/>
              </html-el:link>
          </html-el:radio>
        </td>
        <td class="labelField" width="30%" > &nbsp;&nbsp</td>
     </tr>

      <tr> 
          <td class="label" width="20%"> &nbsp;
          </td>
          <td class="labelField" width="20%"> &nbsp;&nbsp;&nbsp;&nbsp
            <bean-el:message bundle='cm.messages' key='cm.content.search.curversion' />
     <c:choose>
       <c:when test="${cmBasicSearchForm.map.type=='1'}">
            <html-el:radio property="curVersion" value="0" disabled="true"/><bean-el:message bundle='cm.messages' key='cm.content.search.yes'/>&nbsp;<html-el:radio property="curVersion" value="1" disabled="true" /><bean-el:message bundle='cm.messages' key='cm.content.search.no' />
       </c:when>
       <c:otherwise>
            <html-el:radio property="curVersion" value="0" /><bean-el:message bundle='cm.messages' key='cm.content.search.yes'/>&nbsp;<html-el:radio property="curVersion" value="1"/><bean-el:message bundle='cm.messages' key='cm.content.search.no' />

       </c:otherwise>
     </c:choose>
          </td>
        <td class="labelField" width="20%" > &nbsp;&nbsp</td>
        </tr>
    <tr> 
       <td class="label" width="20%">
	&nbsp;&nbsp
       </td>
      <td width="20%" class="labelfield">&nbsp;&nbsp;&nbsp;&nbsp
            <bean-el:message bundle='cm.messages' key='cm.content.search.sortby'/>
        <html-el:select name ="searchResultView" property="sortBy" size="1">
	<html-el:option value=""><bean-el:message bundle='cm.messages' key='cm.content.search.option.nosort' /></html-el:option>
        <html-el:option value="contentName"><bean-el:message bundle='cm.messages' key='cm.content.contentName'/></html-el:option>
        <html-el:option value="version"><bean-el:message bundle='cm.messages' key='cm.content.version'/></html-el:option>
        <html-el:option value="contentObjectType"><bean-el:message bundle='cm.messages' key='cm.content.type' /></html-el:option>
        <html-el:option value="versionCreatedTime"><bean-el:message bundle='cm.messages' key='cm.content.modifiedOn' /></html-el:option>
        <html-el:option value="checkedOutBy"><bean-el:message bundle='cm.messages' key='cm.content.checkedOutBy' /></html-el:option>
        <html-el:option value="processInstanceName"><bean-el:message bundle='cm.messages' key='cm.content.processInstanceName' /></html-el:option>
        </html-el:select>
       <c:if test="${cmBasicSearchForm.map.type=='1'}">
           <script>
			document.cmBasicSearchForm.sortBy.disabled = true;
		   </script>
       </c:if>

        </td>
        <td class="labelField" width="20%" > &nbsp;&nbsp</td>
       </tr>
       <tr>
        <td class="label" width="20%"> 
            <bean-el:message bundle='cm.messages' key='cm.content.search.rows'/>:
        </td>
       <td class="labelField" width="30%">
        <html-el:select name ="searchResultView" property="limitPerPage" size="1" >
        <html-el:option value="10">10</html-el:option>
        <html-el:option value="20">20</html-el:option>
        <html-el:option value="30">30</html-el:option>
        <html-el:option value="50">50</html-el:option>
        <html-el:option value="100">100</html-el:option>
        </html-el:select>
      </td>
        <td class="labelField" width="50%" > &nbsp;&nbsp</td>
    </tr>
        
  </table>
  <div class="pageButtonWrap" align="right">
   <input type="button" name="results" class="inputButton"  onClick="return onSubmit(this.form)"
                value="<bean-el:message bundle='cm.messages' key='button.showResults'/>">
  </div>  
      
  <br>

<c:if test="${searchResultView.map.searchResultMsg== 'ShowResults'}">  

  <div class="pageSubtitle">
    <span class="left"><bean-el:message bundle='cm.messages' key='cm.content.search.searchResultFound' arg0="<%= totalCount.toString() %>" /></span>
    <span class="right">&nbsp;</span>
  </div>
 <c:if test="${cmBasicSearchForm.map.type == '1'}">   
  <table class="dataTable" border="0" cellspacing="1" cellpadding="2" width="100%" summary="<bean-el:message bundle='cm.messages' key='cm.content.search.resultList'/>">
  <tr class="listHeader"> 
    <th id="Content Name" align="left"><bean-el:message bundle='cm.messages' key='cm.content.contentName'/></th>
    <th id="Creation Time" align="left"><bean-el:message bundle='cm.messages' key='cm.content.search.creationtime'/></th>
    <th id="Last Modification Time" align="left"><bean-el:message bundle='cm.messages' key='cm.content.search.lastmodtime'/></th>
    <th id="Action" align="left"><bean-el:message bundle='cm.messages' key='cm.content.search.action'/></th>
  </tr>     
  
  <c:if test="${resultSize == '0'}">
  <tr class="listEven"> 
    <td colspan="8" valign="top" align="center"><bean-el:message bundle='cm.messages' key='cm.content.noContentFound'/></td>
  </tr>
  </c:if>

 <c:forEach var="result" items="${searchResultView.map.resultList}" varStatus="status"> 
   <c:choose>
     <c:when test="${(status.count+1) % 2 == 0}">
           <tr class="listEven">
     </c:when>
         <c:otherwise>
           <tr class="listOdd">
         </c:otherwise>
   </c:choose>
      <td headers="Content Name" align="left">
      <a href="JavaScript:doBVAction(document.cmBasicSearchForm,'<c:out value="${result.map.oid}"/>','<c:out value="${result.map.cntTypeId}"/>','','ViewContent')" >
	  <c:out value="${result.map.name}"/> </a>
      </td>
      <td headers="Creation Time" align="left">
	  <c:out value="${result.map.createtime}"/>
      </td>
      <td headers="Last Modification Time" align="left">
	  <c:out value="${result.map.lastmodtime}"/>
      </td>
      <td headers="Action" align="left" nowrap>
      <a href="JavaScript:doBVAction(document.cmBasicSearchForm,'<c:out value="${result.map.oid}"/>','<c:out value="${result.map.cntTypeId}"/>','','ViewContent')" >
      <img src="<%=ctxPath%>/mc/images/action/icon_view.gif" width="15" height="15" border="0" class="actionIcon" alt='<bean-el:message bundle="cm.messages" key="image.alt.view"/>' title='<bean-el:message bundle="cm.messages" key="image.alt.view"/>'></a>
      <a href="JavaScript:doBVAction(document.cmBasicSearchForm,'<c:out value="${result.map.oid}"/>','<c:out value="${result.map.cntTypeId}"/>','','EditContent')" >
      <img src="<%=ctxPath%>/mc/images/action/icon_edit.gif" width="15" height="15" border="0" class="actionIcon" alt='<bean-el:message bundle="cm.messages" key="image.alt.edit"/>' title='<bean-el:message bundle="cm.messages" key="image.alt.edit"/>'></a>
      <a href="JavaScript:doBVAction(document.cmBasicSearchForm,'<c:out value="${result.map.oid}"/>','<c:out value="${result.map.cntTypeId}"/>','','DeleteContent')" >
      <img src="<%=ctxPath%>/mc/images/action/icon_delete.gif" width="15" height="15" border="0" class="actionIcon" alt='<bean-el:message bundle="cm.messages" key="image.alt.delete"/>' title='<bean-el:message bundle="cm.messages" key="image.alt.delete"/>'></a>
      </td>
    </tr>

   </c:forEach>
  </table>

  </c:if>

 <c:if test="${cmBasicSearchForm.map.type == '0'}">   

  <table class="dataTable" border="0" cellspacing="1" cellpadding="2" width="100%" summary="<bean-el:message bundle='cm.messages' key='cm.content.searchResultList' />">
  <tr class="listHeader"> 
    <th id="Content Name" align="left"><bean-el:message bundle='cm.messages' key='cm.content.contentName' /></th>
    <th id="Version" align="left"><bean-el:message bundle='cm.messages' key='cm.content.version' /></th>
    <th id="Type" align="left" nowrap><bean-el:message bundle='cm.messages' key='cm.content.type' /></th>
    <th id="Modified on" align="left" nowrap><bean-el:message bundle='cm.messages' key='cm.content.modifiedOn' /></th>
    <th id="Modified by" align="left" nowrap><bean-el:message bundle='cm.messages' key='cm.content.modifiedBy' /></th>
    <th id="Checked out by" align="left" nowrap><bean-el:message bundle='cm.messages' key='cm.content.checkedOutBy'/></th>
    <th id="Process Instance" align="left" nowrap><bean-el:message bundle='cm.messages' key='cm.content.processInstance'/></th>
    <th id="Action" align="left"><bean-el:message bundle='cm.messages' key='cm.browse.actions'/></th>
  </tr>     
  
  <c:if test="${resultSize == '0'}">
  <tr class="listEven"> 
    <td colspan="8" valign="top" align="center"><bean-el:message bundle='cm.messages' key='cm.content.noContentFound' /></td>
  </tr>
  </c:if>

 <c:forEach var="result" items="${searchResultView.map.resultList}" varStatus="status"> 
   <c:choose>
     <c:when test="${(status.count+1) % 2 == 0}">
           <tr class="listEven">
     </c:when>
         <c:otherwise>
           <tr class="listOdd">
         </c:otherwise>
   </c:choose>
      <td headers="Content Name" align="left">
       <c:choose>
        <c:when test="${result.map.attachment=='false'}">
      <a href="JavaScript:doWebflowAction(document.cmBasicSearchForm,'<c:out value="${result.map.oid}"/>','<c:out value="${result.map.version}"/>','View')" >
 	<c:out value="${result.map.contentName}"/>
      </a>
      </c:when>
      <c:otherwise>
       <a href="#" onclick='javascript:doAttachment(document.cmBasicSearchForm,"<c:out value='${result.map.urlParams}'/>")'> <c:out value="${result.map.contentName}" /></a>
      </c:otherwise>
	</c:choose>
      </td>
      <td headers="Version"><c:out value="${result.map.version}"/></td>
      <td headers="Type" align="center"><c:out value="${result.map.contentObjectType}" /></td>
      <td headers="Modified on"><c:out value="${result.map.versionCreatedTime}"/></td>
      <td headers="Modified by"><c:out value="${result.map.versionCreatedBy}"/></td>
      <td headers="Checked out by" align="center"><c:out value="${result.map.checkedOutBy}"/></td>
      <td headers="Process Instance" align="center">
      <html-el:link page="/cm/processInstance.do?" name="result" property="procUrlParams">
        <c:out value="${result.map.processInstanceName}"/>
      </html-el:link>
      </td>
      <td headers="Action" align="left" nowrap>
<c:if test="${result.map.contentObjectType == 'BV_XML'}">
      <a href="JavaScript:doWebflowAction(document.cmBasicSearchForm,'<c:out value="${result.map.oid}"/>','<c:out value="${result.map.version}"/>','View')" >
      <img src="<%=ctxPath%>/mc/images/action/icon_view.gif" width="15" height="15" border="0" class="actionIcon" alt='<bean-el:message bundle="cm.messages" key="image.alt.view"/>' title='<bean-el:message bundle="cm.messages" key="image.alt.view"/>'></a>
      <a href="JavaScript:doWebflowAction(document.cmBasicSearchForm,'<c:out value="${result.map.oid}"/>','<c:out value="${result.map.version}"/>','Edit')" >
      <img src="<%=ctxPath%>/mc/images/action/icon_edit.gif" width="15" height="15" border="0" class="actionIcon" alt='<bean-el:message bundle="cm.messages" key="image.alt.edit"/>' title='<bean-el:message bundle="cm.messages" key="image.alt.edit"/>'></a>
      <a href="JavaScript:doAction(document.cmBasicSearchForm,'<c:out value="${result.map.oid}"/>','<c:out value="${result.map.version}"/>','Review')" >
      <img src="<%=ctxPath%>/mc/images/action/icon_launch.gif" width="15" height="15" border="0" class="actionIcon" alt='<bean-el:message bundle="cm.messages" key="image.alt.launch"/>' title='<bean-el:message bundle="cm.messages" key="image.alt.launch"/>'></a>
      <c:if test="${cmContentAdmin == 'true'}">
      <a href="JavaScript:doUncheckout(document.cmBasicSearchForm, '<c:out value="${result.map.oid}"/>')">
      <img src="<%=ctxPath%>/mc/images/action/icon_uncheckout.gif" width="15" height="15" border="0" class="actionIcon" alt='<bean-el:message bundle="cm.messages" key="image.alt.uncheckout"/>' title='<bean-el:message bundle="cm.messages" key="image.alt.uncheckout"/>'></a>      
      </c:if>
     <a href="JavaScript:doWebflowAction(document.cmBasicSearchForm,'<c:out value="${result.map.oid}"/>','<c:out value="${result.map.version}"/>','Delete')" >
      <img src="<%=ctxPath%>/mc/images/action/icon_delete.gif" width="15" height="15" border="0" class="actionIcon" alt='<bean-el:message bundle="cm.messages" key="image.alt.delete"/>' title='<bean-el:message bundle="cm.messages" key="image.alt.delete"/>'></a>
</c:if>
      </td>
      
    </tr>
 </c:forEach>
  </table>

</c:if>
</c:if>

<c:if test="${searchResultView.map.pagination == '1'}">
   
  <div class="pagination">
    <bean-el:message key="cm.common.pagination.show" bundle="cm.messages"/>
      <html-el:select property="entriesPerPageCnt" size="1" onchange="doGoCnt('cmBasicSearchForm')">
        <html-el:option value="10">10</html-el:option>
        <html-el:option value="20">20</html-el:option>
        <html-el:option value="30">30</html-el:option>
        <html-el:option value="50">50</html-el:option>
        <html-el:option value="100">100</html-el:option>
      </html-el:select>
      <bean-el:message key="cm.common.pagination.itemsPerPage" bundle="cm.messages"/>
      &nbsp;&nbsp; 
   <% 
     Integer currentPageNumberInt = (Integer) PropertyUtils.getSimpleProperty(view, "currPageNum"); 
     Integer totalPageNumberInt = (Integer) PropertyUtils.getSimpleProperty(view, "totalPageNum"); 
   %>
   

 <c:if test="${searchResultView.map.currPageNum >1}">  
    <a href="#" class="paginationBtn" onclick="javascript:gotoPage('cmBasicSearchForm', 1)"><bean-el:message bundle='cm.messages' key='cm.common.pagination.first'/></a>
    <a href="#" class="paginationBtn" onclick="javascript:gotoPage('cmBasicSearchForm', <%= currentPageNumberInt.intValue()-1 %>)"><bean-el:message bundle='cm.messages' key='cm.common.pagination.previous'/></a>
  </c:if>

  <bean-el:message bundle='cm.messages' key='cm.common.pagination.pageOf' arg0="<%= currentPageNumberInt.toString() %>" arg1="<%= totalPageNumberInt.toString() %>"/>

 <c:if test="${searchResultView.map.currPageNum < searchResultView.map.totalPageNum}">  
    <a href="#" class="paginationBtn" onclick="javascript:gotoPage('cmBasicSearchForm', <%= currentPageNumberInt.intValue()+1 %>)"><bean-el:message bundle='cm.messages' key='cm.common.pagination.next'/></a>
    <a href="#" class="paginationBtn" onclick="javascript:gotoPage('cmBasicSearchForm', <%= totalPageNumberInt.intValue() %>)"><bean-el:message bundle='cm.messages' key='cm.common.pagination.last'/></a>
  </c:if>
  </div>
</c:if>

 </td>
 </tr>
   </table>
 </html-el:form>


